from mediator import mediator
from mediator . tests . test_assistant import make_mediator_test_keyword_args

class table_gui_fake :
    def __init__ ( self ) :
        self . _bold_table_row = [ ]
        self . _unbold_table_row = [ ]
        self . _gui_create_label_reply = None
        self . _gui_create_entry_reply = None
        self . _gui_mouse_button_1_event_reply = None
        self . _add_table_entry_request = False
    def add_table_entry_request ( self ) :
        self . _add_table_entry_request = True
    def add_table_label ( self , text , anchor , borderwidth ) :
        self . _added_table_label_args = [ text , anchor , borderwidth ]
    def bold_table_row ( self , row ) :
        self . _bold_table_row += [ row ]
    def create_new_table_in_frame ( self , frame ) :
        self . _frame_for_new_table = frame
    def finish_table_row ( self ) :
        self . _table_row_finished = True
    def select_table_row ( self , row ) :
        self . _selected_table_row = row
    def unbold_table_row ( self , row ) :
        self . _unbold_table_row += [ row ]
    def unselect_table_row ( self , row ) :
        self . _unselected_table_row = row
    def gui_create_label_reply ( self , label ) :
        self . _gui_create_label_reply = label
    def gui_create_entry_reply ( self , entry ) :
        self . _gui_create_entry_reply = entry
    def gui_mouse_button_1_event_reply ( self , event ) :
        self . _gui_mouse_button_1_event_reply = event

class arbitrary_module_fake :
    def gui_create_label_reply ( self , label ) :
        pass
    def gui_create_entry_reply ( self , entry ) :
        pass

class mediator_table_gui_tests : 
    'mediator_table_gui'
    def __init__ ( self , test ) :
        self . _test = test
        self . _table_gui = table_gui_fake ( )
        self . _mediator = mediator ( )
        self . _mediator . register_modules ( ** make_mediator_test_keyword_args \
            ( 'table_gui' 
            , self . _table_gui
            , arbitrary_module_fake
            ) )
    def test_unselect_table_row ( self ) :
        self . _mediator . unselect_table_row ( 'my row' )
        self . _test . assume_equal ( self . _table_gui . _unselected_table_row , 'my row' )    
    def test_select_table_row ( self ) :
        self . _mediator . select_table_row ( 'my row' )
        self . _test . assume_equal ( self . _table_gui . _selected_table_row , 'my row' )    
    def test_finish_table_row ( self ) :
        self . _mediator . finish_table_row ( )
        self . _test . assume_true ( self . _table_gui . _table_row_finished )    
    def test_create_new_table_in_frame ( self ) :
        self . _mediator . create_new_table_in_frame ( 'my frame' )
        self . _test . assume_equal ( self . _table_gui . _frame_for_new_table , 'my frame' )    
    def test_add_table_label_default_args ( self ) :
        self . _mediator . add_table_label ( )
        self . _test . assume_equal ( self . _table_gui . _added_table_label_args ,
            [ None
            , None
            , None
            ] )    
    def test_add_table_label_keyword_args ( self ) :
        self . _mediator . add_table_label \
            ( text = 'my text'
            , anchor = 'my anchor'
            , borderwidth = 'my borderwidth'
            )
        self . _test . assume_equal ( self . _table_gui . _added_table_label_args ,
            [ 'my text'
            , 'my anchor'
            , 'my borderwidth'
            ] )
    def test_add_table_label_ordered_args ( self ) :
        self . _mediator . add_table_label \
            ( 'my text'
            , 'my anchor'
            , 'my borderwidth'
            )
        self . _test . assume_equal ( self . _table_gui . _added_table_label_args ,
            [ 'my text'
            , 'my anchor'
            , 'my borderwidth'
            ] )    
    def test_add_table_entry_request ( self ) :
        self . _mediator . add_table_entry_request ( )
        self . _test . assume_true ( self . _table_gui . _add_table_entry_request )    
    def test_bold_table_row ( self ) :
        self . _mediator . bold_table_row ( 'my row' )
        self . _test . assume_equal ( self . _table_gui . _bold_table_row , [ 'my row' ] )
    def test_unbold_table_row ( self ) :
        self . _mediator . unbold_table_row ( 'my row' )
        self . _test . assume_equal ( self . _table_gui . _unbold_table_row , [ 'my row' ] )
    def test_gui_create_label_reply ( self ) :
        self . _mediator . gui_create_label_reply ( 'my label' )
        self . _test . assume_equal ( self . _table_gui . _gui_create_label_reply , 'my label' )
    def test_gui_create_entry_reply ( self ) :
        self . _mediator . gui_create_entry_reply ( 'my entry' )
        self . _test . assume_equal ( self . _table_gui . _gui_create_entry_reply , 'my entry' )
    def test_gui_mouse_button_1_event_reply ( self ) :
        self . _mediator . gui_mouse_button_1_event_reply ( 'my mouse button 1' )
        self . _test . assume_equal ( self . _table_gui . _gui_mouse_button_1_event_reply , 'my mouse button 1' )
